﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PCS_Linh.lab03
{
    class FindElementNumBerOfVariable
    {
        public void run()
        {
            //nhap so phan tu cua mang
            Console.Write("Nhap so phan tu cua mang: ");
            int n = Convert.ToInt32(Console.ReadLine());

            //nhap so
            Array a = Array.CreateInstance(typeof(int), n);
            for (int i = 0; i < n; i++)
            {
                Console.Write("Nhap so a[{0}]: ", i);
                a.SetValue(Convert.ToInt32(Console.ReadLine()), i);
            }

            //mang la
            Console.WriteLine("Mang la: ");
            foreach (int item in a)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            //nhap so cua bien
            Console.Write("Nhap so cua bien: ");
            int m = Convert.ToInt32(Console.ReadLine());

            //tim so phan tu dau tien va cuoi cung cua bien trong mang
            if (Array.IndexOf(a,m) == -1)
            {
                Console.WriteLine("Khong co trong mang!");
            }
            else
            {
                Console.WriteLine("So phan tu dau tien la: " + Array.IndexOf(a,m));
                Console.WriteLine("So phan tu cuoi cung la: " + Array.LastIndexOf(a,m));
            }
        }
    }
}
